package com.cosina.game.crystallight.ui.activity;

import android.view.Menu;
import android.view.MenuItem;

import com.cosina.game.crystallight.CrystalLightActivity;
import com.cosina.game.crystallight.R;
import com.cosina.game.crystallight.util.World;

public class ActivityStatus {
	
	public static final int PAUSE = -1;
	public static final int LOADING = -2;
	public static final int RUNNING = -3;
	
	public static int current = RUNNING;
	public static int soundOn = World.YES;
	 int volume = 5;
	 
	public static final int volumeMax = 11;
	private static final int activty2RunMenuId = 0;
	private static final int activty2PauseMenuId = 1;
	private static final int sound2OnMenuId = 2;
	private static final int sound2OffMenuId = 3;
	
	
	public boolean isRunning(){
		return current == RUNNING;
	}
	
	public boolean isSoundOn(){
		return soundOn == World.YES;
	}
	
	private CrystalLightActivity context;
	
	public ActivityStatus(CrystalLightActivity context) {
		this.context = context;
	}

	public boolean onOptionsItemSelected(MenuItem item){
		switch (item.getItemId()) {
		case activty2RunMenuId:
			context.statusView.invalidate();
			current = RUNNING;
			return true;
		case activty2PauseMenuId:
			context.statusView.invalidate();
			current = RUNNING;
			return true;
		case sound2OnMenuId:
			soundOn = World.YES;
			return true;
		case sound2OffMenuId:
			soundOn = World.NO;
			return true;
		}
		return true;
	}
	
	public boolean menuPrepareProxy(Menu menu){
		menu.clear();
		if (current == RUNNING) {
			MenuItem menuItem = menu.add(Menu.NONE, activty2PauseMenuId,
					Menu.NONE, "Pause");
			menuItem.setIcon(R.drawable.pause);
		} else {
			MenuItem menuItem = menu.add(Menu.NONE, activty2RunMenuId,
					Menu.NONE, "Resume");
			menuItem.setIcon(R.drawable.resume);
		}
		if (soundOn == World.YES) {
			MenuItem menuItem = menu.add(Menu.NONE, sound2OffMenuId, Menu.NONE,
					"Sound off");
			menuItem.setIcon(R.drawable.soundoff);
		} else {
			MenuItem menuItem = menu.add(Menu.NONE, sound2OnMenuId, Menu.NONE,
					"Sound On");
			menuItem.setIcon(R.drawable.soundon);
		}
		return true;
	}

	public void tryVolumeUp() {
		if(volume < volumeMax){
			volume ++;
			context.statusView.invalidateVolume();
		}
	}

	public void tryVolumeDown() {
		if(volume > 0){
			volume --;
			context.statusView.invalidateVolume();
		}
	}
}
